import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
  UseInterceptors,
  UploadedFile,
  UploadedFiles,
  Session,
  Req,
} from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiConsumes,
} from '@nestjs/swagger';
import { Request } from 'express';
import { JwtAuthGuard } from '@wwjCommon/security/guards/jwt-auth.guard';
import { RolesGuard } from '@wwjCommon/security/guards/roles.guard';
import { Roles } from '@wwjCommon/security/decorators/roles.decorator';
import { Public } from '@wwjCommon/security/decorators/public.decorator';
import { BusinessException } from '@wwjCommon/exception/business.exception';
// @UploadedFile() - 单文件上传，配合 @UseInterceptors(FileInterceptor('file'))
// @UploadedFiles() - 多文件上传，配合 @UseInterceptors(FilesInterceptor('files'))
// @Session() - 获取会话对象，对应PHP Session::get()
// @Req() - 获取Request对象，对应PHP Request

/**
 * ScheduleLogController
 * 对应 PHP: ScheduleLog Controller
 * 对应 Java: @RestController
 *
 * 支持装饰器：
 * - @UploadedFile() - 单文件上传 (对应PHP Request::file())
 * - @UploadedFiles() - 多文件上传
 * - @Session() - 会话管理 (对应PHP Session::get())
 * - @Req() - 请求对象 (对应PHP Request)
 */
@ApiTags('sys')
@Controller('adminapi/sys')
export class ScheduleLogController {
  constructor() {}

  /**
   * 计划任务执行记录
   * 路由: GET schedule/log/list
   * PHP路由: Route::get('schedule/log/list', 'sys.ScheduleLog/lists')
   */
  @Get('schedule/log/list')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '计划任务执行记录' })
  async lists(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: lists

      return await this.scheduleLogService.getPage(data);
    } catch (error) {
      throw new BusinessException('lists操作失败', error);
    }
  }

  /**
   * 计划任务执行记录
   * 路由: PUT schedule/log/delete
   * PHP路由: Route::put('schedule/log/delete', 'sys.ScheduleLog/del')
   */
  @Put('schedule/log/delete')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '计划任务执行记录' })
  async del(@Body() data: DelDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: del

      return await this.scheduleLogService.del(data['ids']);
    } catch (error) {
      throw new BusinessException('del操作失败', error);
    }
  }

  /**
   * 计划任务执行记录
   * 路由: PUT schedule/log/clear
   * PHP路由: Route::put('schedule/log/clear', 'sys.ScheduleLog/clear')
   */
  @Put('schedule/log/clear')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '计划任务执行记录' })
  async clear(@Body() data: ClearDto): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: clear

      return await this.scheduleLogService.clear(data);
    } catch (error) {
      throw new BusinessException('clear操作失败', error);
    }
  }
}
